<?php

	include("common.php");
	
	if(!empty($_POST)){
		mysql_query("UPDATE `197_albums` SET `title` = '" . $_POST['title'] . "', `description` = '" . $_POST['description'] . "' WHERE `album_id` = " . $_POST['album_id']);
		include("header.php");
?>
<?php if(!AJAX){ ?><h1>修改相簿</h1><?php } ?>
<p>修改成功<?php if(!AJAX){ ?>，請<a href="albumFind.php">按此</a>返回<?php } ?>。</p>
<?php

		include("sidebar.php");
		include("footer.php");
		
		exit;

	}
	
	$result = mysql_query("SELECT * FROM `197_albums` WHERE `album_id` = " . $_GET['album_id']);
	$row = mysql_fetch_assoc($result);
	
?>
<?php include("header.php"); ?>
<h1>修改相簿</h1>
<div id="edit-result-dialog">
</div>
<script type="text/javascript" defer="defer">
	$("#edit-result-dialog").dialog({
		width: 300,
		height: 210,
		autoOpen: false,
		title: "修改相簿",
		modal: true,
		draggable: false,
		resizable: false
	});
	function editAlbum(){
		$("#edit-result-dialog").dialog("option", "buttons", { "關閉": function(){ location.replace("albumFind.php"); } });
		$("#edit-result-dialog").html("<img src='../images/ajax-loader.gif' />");
		$("#edit-result-dialog").dialog("open");
		$.post("albumEdit.php?ajax=true", $("#album-edit-form").serialize(), function(r){ $("#edit-result-dialog").html(r) });
	}
</script>
<form action="#" id="album-edit-form" onsubmit="editAlbum(); return false;" method="POST">
	<input type="hidden" name="album_id" id="album_id" value="<?php echo $row['album_id']; ?>" />
	<p><label>標題：<input type="text" value="<?php echo $row['title']; ?>" name="title" id="title" /></label></p>
	<p><label>描述：<input type="text" value="<?php echo $row['description']; ?>" name="description" id="description" size="50" /></label></p>
	<p><button class="custom" onclick="$('#album-edit-form').submit();">修改</button>｜<a href="albumFind.php">返回</a></p>
</form>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>